#include <iostream>
#include <string>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

std::string terminal = "/dev/pts/1";
//ls /dev/pts/  来查看有哪些终端
//0 1 .... ptmx
//echo hahah > /dev/pts/(0~...) 来确定终端对应的路径
//这样就可以做的在一个终端发消息，另一个终端收到消息
int OpenTerminal()
{
    int fd = open(terminal.c_str(), O_WRONLY);
    if(fd < 0)
    {
        std::cerr << "open terminal error" << std::endl;
        return 1;
    }
    dup2(fd, 2);
    //newfd成为oldfd（前老后新）的副本，必要时先关闭newfd

    // printf("hello world\n");
    // close(fd);
    return 0;
}